package com.ywjt.pinkelephant.home.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ywjt.pinkelephant.R;
import com.ywjt.pinkelephant.base.BaseActivity;
import com.ywjt.pinkelephant.widget.BackBottomDialog;

import org.w3c.dom.Text;

public class ActivityAddNewText extends BaseActivity implements View.OnClickListener {

   private ImageView    _barBack;
   private ImageView ivVoice;
   private TextView tvVoiceInput;


    public static void actionStart(Context context ) {
        Intent intent = new Intent(context, ActivityAddNewText.class);
        context.startActivity(intent);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id._barBack:
                BackBottomDialog backBottomDialog=new BackBottomDialog();
                backBottomDialog.setClicklistener(new BackBottomDialog.ClickListenerInterface() {
                    @Override
                    public void takePhoto() {
                        //保存并退出
                        finish();
                    }

                    @Override
                    public void selectFromAlbum() {
                        //直接退出
                        finish();
                    }
                });
                backBottomDialog.show(getSupportFragmentManager());
                break;
            case R.id.tvVoiceInput:
                //语音输入
                ivVoice.setVisibility(View.VISIBLE);
                break;
            case R.id.ivVoice:
                ivVoice.setVisibility(View.GONE);
                break;
        }
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        setAndroidNativeLightStatusBar(true);
    }

    @Override
    protected int setLayoutResourceID() {
        return R.layout.activity_addnewtext;
    }

    @Override
    protected void initView() {
        setTitleText("新建台本");
        _barBack=findViewById(R.id._barBack);
        ivVoice=findViewById(R.id.ivVoice);
        tvVoiceInput=findViewById(R.id.tvVoiceInput);

        _barBack.setOnClickListener(this::onClick);
        tvVoiceInput.setOnClickListener(this::onClick);
        ivVoice.setOnClickListener(this::onClick);

    }

    @Override
    protected void initData() {

    }

    /**
     * 获取要使用的标题栏样式(此函数由子类重写)
     * @return
     */
    @Override
    protected int getTitleBarType() {
        return 0;
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            BackBottomDialog backBottomDialog=new BackBottomDialog();
            backBottomDialog.setClicklistener(new BackBottomDialog.ClickListenerInterface() {
                @Override
                public void takePhoto() {
                    //保存并退出
                    finish();
                }

                @Override
                public void selectFromAlbum() {
                    //直接退出
                    finish();
                }
            });
            backBottomDialog.show(getSupportFragmentManager());
        }
        return false;
    }
}
